package utils
{
	import flash.filesystem.File;
	import flash.filesystem.FileMode;
	import flash.filesystem.FileStream;
	import flash.net.FileReference;
	import flash.utils.Dictionary;
	
	dynamic public class config extends Dictionary
	{

		public function config(fname:String = null)
		{
			try{
				var file:File = new File(fname);
				var fs:FileStream = new FileStream();
				fs.open(file, FileMode.READ);
	
				var string:String = fs.readUTFBytes(fs.bytesAvailable);
				var object:Array = string.split("\r\n");
				while(object.length != 0){
					var str:String = object.shift();
					if(isComment(str)) continue;
					this[str.split(" ")[0]] = str.split(" ")[1];
				}
				fs.close();
				fs = null;
				file = null;
			}catch(e:Error){
				Debug.FATAL(e);
				trace(e);
			}
		}
		
		private function isComment (str:String):Boolean
		{
			if (2 > str.length) return true;
			if (str.charAt(0) == "-" || str.charAt(0) == "/") return true;
			return false;
		}
		
		public function Get(key:String):String
		{
			return this[key];
		}
	}
}